package com.yociyy.api.controller;

import com.yociyy.security.authentication.YoCiUser;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ApiController {

    @GetMapping("/hello")
    public YoCiUser getText() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        if (authentication instanceof OAuth2Authentication) {
            OAuth2Authentication auth2Authentication = (OAuth2Authentication) authentication;
            return (YoCiUser) auth2Authentication.getPrincipal();
        }
        return null;
    }

    @GetMapping("/order")
    public String getOrder() {
        return "Order.";
    }

    @GetMapping("/order01")
    public String getOrder01() {
        return "Order-01.";
    }
}
